<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>原始的ajax</title>
</head>
<script>
    function login() {
        var username = document.getElementById("username").value;
        var passwd = document.getElementById("passwd").value;
        var param = "username=" + username + "&jsp=action&passwd=" + passwd;
        console.log(param);

        //发送ajax,get请求
        var request = new XMLHttpRequest();
        request.open("get", "/jsp?" + param);
        request.send();

        //监听准备状态的改变
        request.onreadystatechange = function () {
            console.log(request.readyState + " >>> "+request.status)
            if (request.readyState == 4 && request.status == 200){
                //controller返回的服务器信息
                var resText = request.responseText
                console.log(resText);
                if (resText != null){
                    alert("登录成功")
                }else {
                    alert("登录失败")
                }
            }
        }
    }
</script>
<body>
    <form action="" method="get">
        用户名: <input type="text" id="username" name="username" placeholder="请输入用户名"><br>
        密 码: <input type="password" id="passwd" name="passwd" placeholder="请输入密码"><br>
        <input type="button" value="登录" onclick="login()">
    </form>
</body>
</html>
